import { getHomeInfo, updateUser } from "@/api/home";
import indexService from "@/serivce/indexService";
import axios from "axios";

const state = {
  homeInfo: [],
  loginLog: []
};
const getters = {
  // 获取系统首页的数据
  gGetHomeInfo(state, getters, rootState) {
    console.log('11',state.homeInfo);
    return state.homeInfo
  },

};

const mutations = {
  // 系统首页数据赋值
  getHomeInfo(state, homeInfo) {
    state.homeInfo = homeInfo
  },
};

const actions = {
  // 发起获取系统首页数据请求 异步
  async getHomeInfo({ commit }) {
    try {
      let result = await indexService.getHomeInfo();
      commit("getHomeInfo", result.data.data)
      console.log('eeee',result);
      return result.data.data
    } catch (error) {
      console.log(error);
    }
  },
  // 发起获取登录日志数据请求 异步
  async getLoginLog({ commit },{currentPage,pageSize}) {
    try {
      let result = await indexService.getLoginLog(currentPage,pageSize);
      return result.data
    } catch (error) {
      console.log(error);
    }
  },
  // 发起修改账户信息请求
  async updateUser({commit},{userId,userName,nickName,email,phonenumber,password}){
    try{
      let result = await indexService.updateUser(userId,userName,nickName,email,phonenumber,password);
      console.log("reslut",result);
      return result
    }catch(err){
      console.log(err);
    }
  }

};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
